﻿/*+===================================================================
File:      BossOne.cpp

Summary:   Định nghĩa các phương thức của CBossOne.
===================================================================+*/

#include "BossOne.h"


CBossOne::CBossOne(CBill* bill, D3DXVECTOR2 pos, int id, int typeId) : CMoveableObject(pos, id, typeId)
{
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_BOSS_ONE_HEART);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_BOSS_ONE_GUN_LEFT_FIRE);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_BOSS_ONE_GUN_LEFT_REFIRE);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_BOSS_ONE_GUN_RIGHT_FIRE);
	CResourcesManager::GetInstance()->GetSprite(ID_SPRITE_BOSS_ONE_GUN_RIGHT_REFIRE);
	m_heart = new CBossOneHeart(D3DXVECTOR2(6546, 126), 0, ID_BOSS_ONE_HEART);
	m_gunLeft = new CBossOneGun(D3DXVECTOR2(6450, 216), 0, ID_BOSS_ONE_GUN_LEFT);
	m_gunRight = new CBossOneGun(D3DXVECTOR2(6506, 214), 0, ID_BOSS_ONE_GUN_RIGHT);
	m_enemy = new CBossOneEnemy(bill, D3DXVECTOR2(6464, 346), 0, ID_BOSS_ONE_ENEMY);
	m_pSprite = m_pResourceManager->GetSprite(ID_SPRITE_BOSS_ONE_DIE);
	Box box{ m_pos.x - 416, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT, 0.0f, 0.0f };
	this->SetBoundBox(box);
}

CBossOne::~CBossOne()
{
	if (m_heart)
		delete m_heart;
	if (m_gunLeft)
		delete m_gunLeft;
	if (m_gunRight)
		delete m_gunRight;
	if (m_enemy)
		delete m_enemy;
}

void CBossOne::Update(float timeFrame)
{
	m_heart->Update(timeFrame);
	m_gunLeft->Update(timeFrame);
	m_gunRight->Update(timeFrame);
	m_enemy->Update(timeFrame);

	if (!m_bIsLive)
		return;

	if (!m_heart->IsLive())
	{
		m_enemy->Destroy();
		m_gunLeft->Kill();
		m_gunRight->Kill();
	}
	if (!m_heart->IsLive() && m_heart->GetTimeDie() < 0.0f)
	{
		this->Kill();
		g_nScore += 1000;
	}
	
	m_pSprite->Update(timeFrame);
}

void CBossOne::UpdateCollision(vector<CGameObject*> vecGameObjs, float timeFrame)
{
	if (!m_bIsLive)
		return;
	m_heart->UpdateCollision(vecGameObjs, timeFrame);
	m_gunLeft->UpdateCollision(vecGameObjs, timeFrame);
	m_gunRight->UpdateCollision(vecGameObjs, timeFrame);
	m_enemy->UpdateCollision(vecGameObjs, timeFrame);
}

void CBossOne::Draw()
{
	D3DXVECTOR2 newPos = CViewport::GetInstance()->TransformMatrix(m_pos);
	m_pSprite->Draw(newPos);
	m_heart->Draw();
	m_gunLeft->Draw();
	m_gunRight->Draw();
	m_enemy->Draw();
}